package cn.tedu._03vehicle.controller;

import cn.tedu._03vehicle.base.response.jsonresulte;
import cn.tedu._03vehicle.pojo.entity.notice;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.tedu._03vehicle.mapper.nmapper;

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/notice")
@Tag(name="公告管理")
@Slf4j

public class ncontroller
{

    @Autowired
    private RedisTemplate<String, Serializable> redisTemplate;

    @Autowired
    private nmapper nmapper;
    @GetMapping("/select")
    @Operation(summary = "查询公告")
    @ApiOperationSupport(order = 10)
    public jsonresulte select()
    {
//        log.info("开始处理查询公告");
//        List<notice> notice = nmapper.list();
//        return jsonresulte.success();
        ValueOperations<String, Serializable> op=redisTemplate.opsForValue();
        Serializable notice = op.get("notice");//获取缓存数据
        if(notice==null)//缓存中没有数据
        {
            List<notice> no = nmapper.list();//查询数据库
            op.set("notice",(Serializable)no,30, TimeUnit.SECONDS);//缓存数据
            return jsonresulte.success(notice);//返回数据
        }
        return jsonresulte.success(notice);
    }
}
